package com.quotes.datamodell;

import java.util.*;
import com.quotes.dates.*;

public class QuotesList
{
	private List<Quotes> list = new ArrayList<Quotes>();

	public QuotesList() {
	}
	
	public void add(Quotes quotes) {
		list.add(quotes);
	}
	
	public List<Quotes> getQuotes() {
		return list;
	}
	
	public Quotes BySymbol(Symbol symbol) {
		for (Quotes quote : list) {
			if (quote.getSymbol().equals(symbol))
				return quote;
		}
		
		return null;
	}
	
	public Quotes byYahooName(String yahooName) {
		for (Quotes quote : list) {
			if (quote.getSymbol().getYahooName() == yahooName)
				return quote;
		}
		
		return null;
	}
	
	public QuotesList byYahooNames(String symbols) {
		QuotesList result = new QuotesList();
		
		for (String symbol : symbols.split(" ")) {
			Quotes quotes = byYahooName(symbol);
			if (quotes != null)
				result.add(quotes);
		}
		
		return result;
	}
	
	public Quotes get(int index) {
		return list.get(index);
	}
	
	public QuotesList extractPeriod(TimeRange range) {
		QuotesList result = new QuotesList();
		
		for (Quotes quotes : list) {
			result.add(quotes.extractPeriod(range));
		}
		
		return result;
	}
	
	public SymbolList getSymbols() {
		SymbolList symbols = new SymbolList();
		
		for (Quotes quotes : list) {
			symbols.add(quotes.getSymbol());
		}
		
		return symbols;
	}
}
